﻿<%@ page contentType="text/html; charset=UTF-8" %>
<div class="searchBar">
登录帐号：<input id="s_user_name" name="s_user_name" type="text" class="box-input">&nbsp;&nbsp;
真实姓名：<input id="s_user_realname" name="s_user_realname" type="text" class="box-input">&nbsp;&nbsp;
所属机构<select id="s_user_company" name="s_user_company"></select>&nbsp;&nbsp;
<input id="s_user" type="button" class="btns" value="查  询">
</div>
<%
   //从登录用户类中取当前用户信息,进行只能操作当前EC机构
   com.health.system.springSecurity.UserInfo userInfo = com.health.system.springSecurity.LogonUser.logonUser();
   String operaCpId = userInfo.getCpId();
   String operaCpCode = userInfo.getCpCode();
%>
<table id="user_grid"></table>      
<div id="user_page"></div>  

<div id="user_dialog_add" title="新增操作员">
<form id="user_form_add" name="user_form_add" style="width:600px;" class="cmxform" method="POST">
    <div id="user_add_errmsg"></div>
    <table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" class="jkt-tableStyle">
    <input type="hidden" id="user_company_add" name="user_company_add" value="<%=operaCpId%>" />
    <input type="hidden" id="user_cpCode_add" name="user_cpCode_add" value="<%=operaCpCode%>" />
	<tr>
        <td class="bluetd" align="right">账号：</td>
        <td class="bluetd">
          <input id="user_name_add" name="user_name_add"/><span class="red-color">*</span>
        </td>
        <td class="bluetd" align="right">密码：</td>
        <td class="bluetd" align="left">
          <input id="user_password_add" name="user_password_add" type='password'/><span class="red-color">*</span>
        </td>
     </tr>
	<tr>
        <td class="bluetd2" align="right">真实姓名：</td>
        <td class="bluetd2" align="left">
          <input id="user_realname_add" name="user_realname_add"/><span class="red-color">*</span>
        </td>
	   <td align="right" class="bluetd2">确认密码：</td>
        <td align="left" class="bluetd2">
          <input id="user_password_add2" name="user_password_add2" type='password'/><span class="red-color">*</span>
       </td>
<!-- 
        <td class="bluetd2" align="right">所属机构：</td>
        <td class="bluetd2" align="left">
         <div class="zTreeDemoBackground">
            <input id="user_citySel_add" type="text" readonly />
			&nbsp;<a id="menuBtn_useradd" href="#" onclick="showUserMenu_add(); return false;">选择</a><span class="red-color">*</span>
			</div>
			<input type="hidden" id="user_company_add" name="user_company_add" value="" />
        </td>
 -->        
     </tr>
	<tr>
        <td class="bluetd" align="right">性别：</td>
        <td class="bluetd" align="left">
          <select style="width:140px" id="user_sex_add" name="user_sex_add">
          <option value="男">男</option>
          <option value="女">女</option>
        </select>
        </td>
        <td class="bluetd" align="right">工作电话：</td>
        <td class="bluetd" align="left">
          <input id="user_worktel_add" name="user_worktel_add"/>
        </td>
     </tr>
 
	<tr>
        <td class="bluetd2" align="right">手机号码：</td>
        <td class="bluetd2" align="left">
          <input id="user_mobiletel1_add" name="user_mobiletel1_add"/>
        </td>
        <td class="bluetd2" align="right">备用手机号：</td>
        <td class="bluetd2" align="left">
          <input id="user_mobiletel2_add" name="user_mobiletel2_add"/>
        </td>
     </tr>
     
	<tr>
        <td class="bluetd" align="right">传真：</td>
        <td class="bluetd" align="left">
          <input id="user_fax_add" name="user_fax_add"/>
        </td>
        <td class="bluetd" align="right">生日：</td>
        <td class="bluetd" align="left">
          <input id="user_birthday_add" name="user_birthday_add"/>
        </td>
     </tr>
	<tr>
        <td class="bluetd2" align="right">电子邮件：</td>
        <td class="bluetd2" align="left">
          <input id="user_email_add" name="user_email_add"/>
        </td>
        <td class="bluetd2" align="right">家庭住址：</td>
        <td class="bluetd2" align="left">
          <input id="user_address_add" name="user_address_add"/>
        </td>
     </tr>
	<tr>
        <td class="bluetd" align="right">邮编：</td>
        <td class="bluetd" align="left">
          <input id="user_postalcode_add" name="user_postalcode_add"/>
        </td>
        <td class="bluetd" align="right">身份证：</td>
        <td class="bluetd" align="left">
          <input id="user_idcard_add" name="user_idcard_add"/>
        </td>
     </tr>
     <tr>
        <td class="bluetd2" align="right">角色：</td>
        <td class="bluetd2" align="left" colspan="3">
          <select id="user_roleId_add" name="user_roleId_add" multiple="multiple" size="5" ></select><span class="red-color">*</span>
        </td>
     </tr>
      <tr>
        <td colspan="4" align="center">
         <input type="button" class="btns" id="user_add_bt" value="新  增" style="margin-top:8px;" />&nbsp;&nbsp;
         <input type="button" class="btns" id="user_add_close" value="关  闭" style="margin-top:8px;" />
      </td>
</tr>
<div id="user_add_dm" style="display:none; position:absolute;height:212px; min-width:150px; background-color:white;border:1px solid;overflow-y:auto;overflow-x:auto;">
	<ul id="user_dMenu_add" class="tree"></ul>
</div>
</table>
</form>
</div> 

<div id="user_dialog_up" title="修改操作员">
<form id="user_form_up" name="user_form_up" style="width:600px;" class="cmxform" method="POST">
    <div id="user_up_errmsg"></div>
    <table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" class="jkt-tableStyle">
    
	<tr>
        <td class="bluetd" align="right">账号：</td>
        <td class="bluetd">
          <input id="user_name_up" name="user_name_up" readonly/><span class="red-color">*</span>
        </td>
        <td class="bluetd" align="right">状态：</td>
        <td class="bluetd" align="left" >
          <select style="width:140px" id="user_blocked_up" name="user_blocked_up">
          <option value="-1">——请选择——</option>
          <option value="1">正常</option>
          <option value="2">开通</option>
          <option value="4">暂停</option>
          <option value="5">停止</option>
        </select><span class="red-color">*</span>
        </td>
     </tr>
	<tr>
        <td class="bluetd2" align="right">真实姓名：</td>
        <td class="bluetd2" align="left">
          <input id="user_realname_up" name="user_realname_up"/><span class="red-color">*</span>
        </td>
        <td class="bluetd2" align="right">所属机构：</td>
        <td class="bluetd2" align="left">
          <div class="zTreeDemoBackground">
            <input id="user_citySel_up" type="text" readonly />
			&nbsp;<a id="menuBtn_userup" href="#" onclick="showUserMenu_up(); return false;">选择</a><span class="red-color">*</span>
			</div>
			<input type="hidden" id="user_company_up" name="user_company_up" value="" />
        </td>
     </tr>
	<tr>
        <td class="bluetd" align="right">性别：</td>
        <td class="bluetd" align="left">
          <select style="width:140px" id="user_sex_up" name="user_sex_up">
          <option value="男">男</option>
          <option value="女">女</option>
        </select>
        </td>
        <td class="bluetd" align="right">工作电话：</td>
        <td class="bluetd" align="left">
          <input id="user_worktel_up" name="user_worktel_up"/>
        </td>
     </tr>
	<tr>
        <td class="bluetd2" align="right">手机号码：</td>
        <td class="bluetd2" align="left">
          <input id="user_mobiletel1_up" name="user_mobiletel1_up"/>
        </td>
        <td class="bluetd2" align="right">备用手机号：</td>
        <td class="bluetd2" align="left">
          <input id="user_mobiletel2_up" name="user_mobiletel2_up"/>
        </td>
     </tr>
	<tr>
        <td class="bluetd" align="right">传真：</td>
        <td class="bluetd" align="left">
          <input id="user_fax_up" name="user_fax_up"/>
        </td>
        <td class="bluetd" align="right">生日：</td>
        <td class="bluetd" align="left">
          <input id="user_birthday_up" name="user_birthday_up"/>
        </td>
     </tr>
	<tr>
        <td class="bluetd2" align="right">电子邮件：</td>
        <td class="bluetd2" align="left">
          <input id="user_email_up" name="user_email_up"/>
        </td>
        <td class="bluetd2" align="right">家庭住址：</td>
        <td class="bluetd2" align="left">
          <input id="user_address_up" name="user_address_up"/>
        </td>
     </tr>
	<tr>
        <td class="bluetd" align="right">邮编：</td>
        <td class="bluetd" align="left">
          <input id="user_postalcode_up" name="user_postalcode_up"/>
        </td>
        <td class="bluetd" align="right">身份证：</td>
        <td class="bluetd" align="left">
          <input id="user_idcard_up" name="user_idcard_up"/>
        </td>
     </tr> 
     <tr>
        <td class="bluetd2" align="right">角色：</td>
        <td class="bluetd2" align="left" colspan="3">
          <select id="user_roleId_up" name="user_roleId_up" multiple="multiple" size="5" ></select><span class="red-color">*</span>
        </td>
     </tr>
      <tr>
        <td colspan="4" align="center">
         <input type="button" class="btns" id="user_up_bt" value="修  改" style="margin-top:8px;" />&nbsp;&nbsp;
         <input type="button" class="btns" id="user_up_close" value="关  闭" style="margin-top:8px;" />
      </td>
</tr>
<div id="user_up_dm" style="display:none; position:absolute;height:212px; min-width:150px; background-color:white;border:1px solid;overflow-y:auto;overflow-x:auto;">
	<ul id="user_dMenu_up" class="tree"></ul>
</div>
</table>
</form>
</div> 

<script>

    var userdata={};//本页变量
    userdata.addvalidate;
    userdata.upvalidate;
    userdata.ids='';
    userdata.addset;
    userdata.upset;
    userdata.addNodes=[];
    userdata.upNodes=[];
    userdata.addval=false;
    userdata.upval=false;
    
	jQuery("#user_grid").jqGrid({//列表
        datatype: "json", 
        hidegrid: false, //不显示收缩
        url:'system/User/list.do',
        height:usergridHeight,
        forceFit: true,//调整宽度不改变表格宽度
        width: usergridWidth,
        colNames:[
        '编号'
        ,'账号'
        ,'密码'
        ,'真实姓名'
        ,'性别'
        ,'所属机构ID'
        ,'所属机构'
        ,'工作电话'
        ,'手机号1'
        ,'手机号2'
        ,'传真'
        ,'生日'
        ,'生日1'
        ,'电子邮件'
        ,'家庭住址'
        ,'邮编'
        ,'身份证'
        ,'禁用'
        ,'开通时间'
        ,'最后登录时间'
        ,'登录次数'
        ,'角色'
	    ],
        colModel:[
        {name:'id',index:'id', width:2,sorttype:'int',sortable:false}  
        ,{name:'name',index:'name',width:100,sortable:false}
        ,{name:'password',index:'password',width:2,sortable:false}
        ,{name:'realname',index:'realname',width:100,sortable:false}
        ,{name:'sex',index:'sex',width:2,sortable:false}
        ,{name:'company',index:'company',width:2,sortable:false}
        ,{name:'companyName',index:'companyName',width:140,sortable:false}
        ,{name:'worktel',index:'worktel',width:100,sortable:false}
        ,{name:'mobiletel1',index:'mobiletel1',width:100,sortable:false}
        ,{name:'mobiletel2',index:'mobiletel2',width:2,sortable:false}
        ,{name:'fax',index:'fax',width:2,sortable:false}
        ,{name:'birthday',index:'birthday',width:2,sortable:false}
        ,{name:'birthdayString',index:'birthdayString',width:2,sortable:false}
        ,{name:'email',index:'email',width:2,sortable:false}
        ,{name:'address',index:'address',width:2,sortable:false}
        ,{name:'postalcode',index:'postalcode',width:2,sortable:false}
        ,{name:'idcard',index:'idcard',width:2,sortable:false}
        ,{name:'blocked',index:'blocked',width:90,sortable:false,formatter:fun_user_formatBlocked}
        ,{name:'regdateString',index:'regdateString',width:140,sortable:false,sorttype:'date',datefmt:'y-m-d h:m:s'}
        ,{name:'lastloginDateString',index:'lastloginDateString',width:2,sortable:false}
        ,{name:'logincount',index:'logincount',width:2,sortable:false}
        ,{name:'roleIds',index:'roleIds',width:2,sortable:false}
        ],
        multiselect: true,//禁止多选
        toolbar:[true,'top'],
        rowNum:10, 
        rowList:[5,10,20], 
        viewrecords: true, 
        sortname:  "t.id_" , //默认排序的列名    
        sortorder: "desc", 
        pager: '#user_page', 
        jsonReader: {     
          root: 'dataRows',   
          repeatitems : false     
        }
    })
    
    $("#t_user_grid").append("<div style='width:30%;' class='l'>系统管理->操作员列表</div><div class='r text-r' style='width:60%; height:28px'>"
       +"<a href='javascript:void(0)' onclick=\"fun_user_update()\" class='modify r'>修改</a>"
       +"<a href='javascript:void(0)' onclick=\"fun_user_delete()\" class='del r'>删除</a> "
       +"<a href='javascript:void(0)' onclick=\"fun_user_add()\" class='add r'>新增</a></div>");//列表头
       
    $("#t_user_grid").removeClass("ui-userdata ui-state-default"); //删样式
    $("#t_user_grid").addClass("ui-title ui-corner-top ui-helper-clearfix");//加样式

    jQuery("#user_grid").jqGrid('hideCol',['id','password','company','sex','mobiletel2','fax','birthday','birthdayString','email','address','postalcode','idcard','lastloginDateString','logincount','roleIds']);//隐藏列
    $("#user_grid").closest(".ui-jqgrid-bdiv").css({ 'overflow-x' : 'hidden' });//隐藏横向滚动条
    
    function fun_user_formatBlocked(cellvalue, options, rowObject){
        if(rowObject.blocked==1){
            return ("正常");
        }else if(rowObject.blocked==2){
            return ("开通");
        }else if(rowObject.blocked==4){
            return ("暂停");
        }else{
            return ("停止");
        }
    }
    
    function fun_user_add(){//新增操作
		$("#user_form_add")[0].reset();
		//$("#user_roleId_add").multiselect("uncheckAll");//清空多选框的内容
		userdata.addvalidate.resetForm(); //重置验证状态
		$('#user_add_errmsg').html("");
		userdata.addval=false;
		$("#user_dialog_add").dialog("open");
		$("#user_roleId_add").multiselect("open");
		var arr_check = $("#user_roleId_add > option");
		$("#user_roleId_add").multiselect("refresh");//如果不加载此属性，有时可能列表不显示
		//alert(arr_check.length);
		$("#user_company_add").val(<%=operaCpId%>);
	}
    
    $('#user_add_bt').click(function(){//点击按妞
         if(rulesByValidator(userdata.addvalidate)){
             user_add_submit();
         }
     })
     
     function  user_add_submit(){//新增提交
        var userJson="{'id':'','name':'"+$('#user_name_add').val()+"','password':'"+$('#user_password_add').val()+"','realname':'"+$('#user_realname_add').val()+"','sex':'"+$('#user_sex_add').val()+"','company':'"+$('#user_company_add').val()+"','cpCode':'"+$('#user_cpCode_add').val()+"','worktel':'"+$('#user_worktel_add').val()+"','mobiletel1':'"+$('#user_mobiletel1_add').val()+"','mobiletel2':'','fax':'"+$('#user_fax_add').val()+"','birthdayString':'"+$('#user_birthday_add').val()+"','email':'"+$('#user_email_add').val()+"','address':'"+$('#user_address_add').val()+"','postalcode':'"+$('#user_postalcode_add').val()+"','idcard':'"+$('#user_idcard_add').val()+"','blocked':'1','roleId':'"+$('#user_roleId_add').val()+"'}";  
         $.ajax({
             type: "POST",
             url:"system/User/save.do",
             data:{
                 userJson:userJson
             },
             dataType: "json",
             contentType: "application/x-www-form-urlencoded; charset=UTF-8",
             success:function(json){
                 if(json.success){
                     $("#user_grid").trigger("reloadGrid");
                     alertmsg(json.msg,"info");
                 }else{
                     alertmsg(json.msg,"alert");
                 }                
             }
         })
         
          $("#user_dialog_add").dialog('close');
     }
     
     $('#user_add_close').click(function(){//关闭
         $("#user_dialog_add").dialog('close');
     })
     
     function fun_user_update(){//修改操作
        var id =$("#user_grid").jqGrid('getGridParam','selrow');
        var dataUpdate = $("#user_grid").jqGrid('getGridParam','selarrrow');//'selrow'     
        var lengthUpdate=dataUpdate.length;
        if(lengthUpdate >1){
  	        alertmsg("每次只能修改一条记录!","alert");
  	        return;
  	    }
        if(typeof(id) =="string"){
            rowData=jQuery("#user_grid").jqGrid('getRowData',id);  
		    $("#user_form_up")[0].reset();
		    userdata.upvalidate.resetForm(); //重置验证状态
		    $('#user_up_errmsg').html("");
		    userdata.upval=false;
		    $("#user_dialog_up").dialog("open");
            load_user_data();
        }else{
           alertmsg("请至少选择一条记录再操作!","alert");
        }
	}
	
	function load_user_data(){//加载数据
         $("#user_name_up").val(rowData.name);
         $("#user_realname_up").val(rowData.realname);
         $("#user_sex_up").val(rowData.sex);
         $("#user_citySel_up").val(rowData.companyName);
         $("#user_company_up").val(rowData.company);
         $("#user_worktel_up").val(rowData.worktel);
         $("#user_mobiletel1_up").val(rowData.mobiletel1);
         $("#user_mobiletel2_up").val(rowData.mobiletel2);
         $("#user_fax_up").val(rowData.fax);
         $("#user_birthday_up").val(rowData.birthdayString);
         $("#user_email_up").val(rowData.email);
         $("#user_address_up").val(rowData.address);
         $("#user_postalcode_up").val(rowData.postalcode);
         $("#user_idcard_up").val(rowData.idcard);
         //$("#user_blocked_up").val(rowData.blocked);
         //$("#user_roleId_up").val(rowData.roleIds);
          
         if(rowData.blocked=="正常"){
             $("#user_blocked_up").val(1);
         }else if(rowData.blocked=="开通"){
             $("#user_blocked_up").val(2);
         }else if(rowData.blocked=="暂停"){
             $("#user_blocked_up").val(4);
         }else{
             $("#user_blocked_up").val(5);
         }
         
         var roleIds = rowData.roleIds; //角色
			var arr_roleId = roleIds.split(",");
			for(var i=0;i<arr_roleId.length;i++){
			    var v = $.trim(arr_roleId[i]);
			    var arr_check = $("#user_roleId_up > option");
			    for(var j=0;j<arr_check.length;j++){
			       if(v==$(arr_check[j]).val()){
			         $(arr_check[j]).attr('selected',true);
			       }
			    }
			}
			$("#user_roleId_up").multiselect("refresh");
	}
     
     $('#user_up_bt').click(function(){//点击按妞
         if(rulesByValidator(userdata.upvalidate)){
             user_update_submit();
         }
     })
        
     function  user_update_submit(){//修改提交
     
       // alert("user_roleId_up"+$("#user_roleId_up").val());
     
         var userJson="{'id':'"+rowData.id+"','name':'"+$('#user_name_up').val()+"','realname':'"+$('#user_realname_up').val()+"','sex':'"+$('#user_sex_up').val()+"','company':'"+$('#user_company_up').val()+"','worktel':'"+$('#user_worktel_up').val()+"','mobiletel1':'"+$('#user_mobiletel1_up').val()+"','mobiletel2':'"+$('#user_mobiletel2_up').val()+"','fax':'"+$('#user_fax_up').val()+"','birthdayString':'"+$('#user_birthday_up').val()+"','email':'"+$('#user_email_up').val()+"','upress':'"+$('#user_upress_up').val()+"','postalcode':'"+$('#user_postalcode_up').val()+"','idcard':'"+$('#user_idcard_up').val()+"','blocked':'"+$('#user_blocked_up').val()+"','roleId':'"+$('#user_roleId_up').val()+"'}";  
         $.ajax({
             type: "POST",
             url:"system/User/update.do",
             data:{
                 userJson:userJson
             },
             dataType: "json",
             contentType: "application/x-www-form-urlencoded; charset=UTF-8",
             success:function(json){
                 if(json.success){
                     $("#user_grid").trigger("reloadGrid");
                     alertmsg(json.msg,"info");
                 }else{
                     alertmsg(json.msg,"alert");
                 }
                 $("#user_dialog_up").dialog('close');
             }
        })
     }
     
     $('#user_up_close').click(function(){//关闭
         $("#user_dialog_up").dialog('close');
     })
	 
	 userdata.addvalidate = $("#user_form_add").validate({//新增验证
	        errorElement: "div",
            errorPlacement: function(error, element) {
			    $('#user_add_errmsg').html("");
				error.appendTo( "#user_add_errmsg" );
				userdata.addval=true;
			},
			success: function(label) {
			    label.text("验证通过!").removeClass("error").addClass("success");
			    userdata.addval=true;
			},
	        rules: {
	            user_name_add:{
                    required: true,
                    remote: {
                       url: "system/User/checkUserName.do",
                       type: "post",
                       contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                       data: {userName: function() {
                           return $("#user_name_add").val()},
                            company : function() {
                           return $("#user_company_add").val()}
                       }
                   },
                   nozn:true,
                   string:true
               },
               user_password_add:{
                   required: true,
                   stringMinLength:6,
                   stringMaxLength:16
               },
               user_realname_add:{
                   required: true
               },
               user_company_add:{
                   required: true
               },
               user_roleId_add:{
                   required: true,
				   minlength: 1
               }
	        }, 
	        messages: {
	            user_name_add:{
                    required: "账号不能为空",
                    remote: "账号已存在",
                    nozn:"不能输入汉字",
                    string:"不能输入特殊字符"
                },
                user_password_add:{
                    required: "密码不能为空",
                    stringMinLength:"密码长度最少不能少于6位",
                    stringMaxLength:"密码长度最长不能超过16位"
                },
                user_realname_add:{
                    required: "真实姓名不能为空"
                },
                user_company_add:{
                    required: "所属机构不能为空"
                },
                user_roleId_add: {
			        required: "角色必选",
				    minlength: "最少选一个角色"
			    }
	        },
	        onkeyup:false,
		    onsubmit:false
	})
	
	userdata.upvalidate = $("#user_form_up").validate({//修改验证
	        errorElement: "div",
            errorPlacement: function(error, element) {
			    $('#user_up_errmsg').html("");
				error.appendTo( "#user_up_errmsg" );
	            userdata.upval=true;
			},
			success: function(label) {
			    label.text("验证通过!").removeClass("error").addClass("success");
			    userdata.upval=true;
			},
	        rules: {
               user_realname_up:{
                   required: true
               },
               user_company_up:{
                   required: true,
                   notEqual: "-1"
               },
               user_blocked_up:{
                   required: true,
                   notEqual: "-1"
               },
               user_roleId_up:{
                   required: true,
				   minlength: 1
               }
	        }, 
	        messages: {
                user_realname_up:{
                    required: "真实姓名不能为空"
                },
                user_company_up:{
                    required: "所属公司不能为空",
                    notEqual: "请选择所属公司"
                },
                user_blocked_up:{
                   required: "状态不能为空",
                   notEqual: "请选择状态"
                },
                user_roleId_up: {
			        required: "角色必选",
				    minlength: "最少选一个角色"
			    }
	        },
	        onkeyup:false,
		    onsubmit:false
	})
	
	
	function fun_user_delete(){//删除验证
        var data = $("#user_grid").jqGrid('getGridParam','selarrrow');//'selrow'
        var length=data.length;
        if(length <1){
	        alertmsg("请至少选择一条记录再操作!","alert");
	        return;
	    }
	    userdata.ids='';
	    for(var i=0;i<length;i++){
	        if(i > 0){
                 userdata.ids += ',';
            }
            userdata.ids += data[i];
	    }
        confirm("确认要删除所选记录吗？", fun_user_del);
    }
    
    function fun_user_del(){//删除操作
	    $.ajax({
            type: "POST",
            url:"system/User/delete.do",
            dataType: "json",
            data:{
                 ids:userdata.ids
            },
            success:function(json){
                 if(json.success){
                      alertmsg(json.msg,"info");
                      $("#user_grid").trigger("reloadGrid");
                 }else{
                      alertmsg(json.msg,"alert");
                 }
                 
            }
        })
    }
	
	$("#user_dialog_add").dialog({//弹出层
		 autoOpen: false,
		 height: useraddDialogHeight(),
		 width: 630,
		 modal: true
	});
	
	$("#user_dialog_up").dialog({//弹出层
		 autoOpen: false,
		 height: userupDialogHeight(),
		 width: 630,
		 modal: true
	});
	
	function userupDialogHeight(){//弹出层高度
        if($.browser.mozilla){//火狐
           return 400;
	    }else{//其它
		   return 400;
	    }
    }
	
    function useraddDialogHeight(){//弹出层高度
        if($.browser.mozilla){//火狐
           return 400;
	    }else{//其它
		   return 400;
	    }
    }

	function fun_usergridResize(){
	    jQuery("#user_grid").setGridHeight(mDiv.height-195);
        jQuery("#user_grid").setGridWidth(mDiv.width-22);
	}
	
	$("#westDiv").bind("pageResize",function(event){
		 fun_usergridResize();
	})
	
	function usergridWidth(){    
        mDiv.width-22; 
    }
    
    function usergridHeight(){    
        mDiv.height-195;
    }
	
	fun_usergridResize();
	
	$('#s_user').click(function(){
         var s_name=encodeURI($('#s_user_name').val());
         var s_realname=encodeURI($('#s_user_realname').val());
         var s_company=encodeURI($('#s_user_company').val());
           
         $("#user_grid").setGridParam({url:'system/User/list.do?s_name='+s_name+'&s_realname='+s_realname+'&s_company='+s_company});
         $("#user_grid").trigger("reloadGrid");
    })
    
    
    userdata.addset = {
		isSimpleData: true,
		treeNodeKey: "id",
		treeNodeParentKey: "pId",
		fontCss: setFont,
		expandSpeed : "",
		callback: {
			click: useraddzTreeOnClick
		}
	}
  	 
  	 function useraddzTreeOnClick(event, treeId, treeNode) {
		if (treeNode) {
			var cityObj = $("#user_citySel_add");
			cityObj.attr("value", treeNode.name);
			$("#user_company_add").val(treeNode.id);
			hideUserMenu_add();
		}
	}

	function userloadaddTree() {
		hideUserMenu_add();
		$("#user_dMenu_add").zTree(userdata.addset, userdata.addNodes);
	}

	function showUserMenu_add() {
	    if(userdata.addval){
	        $("#user_add_dm").css({left:"387px", top: "109px"}).slideDown("fast");
	    }else{
	        $("#user_add_dm").css({left:"387px", top: "61px"}).slideDown("fast");
	    }
	}
	
	function hideUserMenu_add() {
		$("#user_add_dm").fadeOut("fast");
	}
  	 
  	 userdata.upset = {
		isSimpleData: true,
		treeNodeKey: "id",
		treeNodeParentKey: "pId",
		fontCss: setFont,
		expandSpeed : "",
		callback: {
			click: userupzTreeOnClick
		}
	}

	function setFont(treeId, treeNode) {
		if (treeNode && treeNode.isParent) {
			return {color: "blue"};
		} else {
			return null;
		}
	}

	function showUserMenu_up() {
	    if(userdata.upval){
	        $("#user_up_dm").css({left:"387px", top: "109px"}).slideDown("fast");
	    }else{
	        $("#user_up_dm").css({left:"387px", top: "61px"}).slideDown("fast");
	    }
	}
	
	function hideUserMenu_up() {
		$("#user_up_dm").fadeOut("fast");
	}

	function userupzTreeOnClick(event, treeId, treeNode) {
		if (treeNode) {
			var cityObj = $("#user_citySel_up");
			cityObj.attr("value", treeNode.name);
			$("#user_company_up").val(treeNode.id);
			hideUserMenu_up();
		}
	}

	function userloadupTree() {
		hideUserMenu_up();
		$("#user_dMenu_up").zTree(userdata.upset, userdata.upNodes);
	}
    
    $(function() {   
    
    $("body").bind("mousedown", 
			function(event){
				if (!(event.target.id == "menuBtn_useradd" || event.target.id == "user_add_dm" || $(event.target).parents("#user_add_dm").length>0)) {
					hideUserMenu_add();
				}
				if (!(event.target.id == "menuBtn_userup" || event.target.id == "user_up_dm" || $(event.target).parents("#user_up_dm").length>0)) {
					hideUserMenu_up();
				}
			});
			
    $.ajax({
            type: "POST",
            url:"organiza/DataOrganizations/getDataOrganizationsTree.do",
            dataType: "json",
            success:function(json){
                 userdata.addNodes =strToObj(json.msg);
                 userdata.upNodes =strToObj(json.msg);
                 userloadaddTree();
		         userloadupTree();
            }
    })
    //取组织机构下拉框数据
    $.ajax({
            type: "POST",
            url:"organiza/DataOrganizations/getDataOrganizationsComboBox.do",
            dataType: "json",
            success:function(json){
            	 $("#s_user_company").html('');
                 $("#s_user_company").append(json.msg);
            }
    })
    
    $.ajax({
            type: "POST",
            url:"system/Role/getRoleComboBox1.do",
            dataType: "json",
            success:function(json){
                 $("#user_roleId_up").html('');
                 $("#user_roleId_add").html('');
                 $("#user_roleId_up").append(json.msg);
                 $("#user_roleId_add").append(json.msg);
            }
     })
     
	     setTimeout(function() {
	     
	        $("#user_roleId_add").multiselect({
               checkAllText: '全选',
               uncheckAllText: '取消',
               noneSelectedText: '请选择',
               selectedList: 1000,
               minWidth: 448,
               height: '150',
               autoOpen:true,  //解决IE6不能一次打开
               position: { 
                   my: 'left bottom', 
                   at: 'left top' 
               }
           })
           $("#user_roleId_up").multiselect({
               checkAllText: '全选',
               uncheckAllText: '取消',
               noneSelectedText: '请选择',
               selectedList: 1000,
               minWidth: 448,
               height: '150',
               autoOpen:true,  //解决IE6不能一次打开
               position: { 
                   my: 'left bottom', 
                   at: 'left top' 
               }
           })
         }, 800)
         
         $("#user_birthday_add").datepicker()
         $("#user_birthday_up").datepicker()
	 })

</script>
